<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<br>
    宽度：<input id="width" type="text"/>
    </br>
    高度：<input id="height" type="text"/>
    </br>
    <input id="calculate" type="button" value="计算"/>
    </br>
    周长：<input id="perimeter" type="text"/>
    </br>
    面积：<input id="area" type="text"/>
</body>
<script>
    function cal(){
        var width=document.getElementById('width').value;
        var height=document.getElementById('height').value;
        var calculate=document.getElementById('calculate');
        var perimeter=document.getElementById('perimeter');
        var area=document.getElementById('area');

        // let per=2*(width+height);
        // let ar=width*height;
        perimeter.value=2*width+2*height;
        area.value=width*height;
        // perimeter.value=per;
        // area.value=ar;
    }
    
    document.querySelector('#calculate').onclick=cal;
</script>
</html>